﻿<%@ Control Language="C#" AutoEventWireup="true" Codebehind="LookupTongHop.ascx.cs" Inherits="CMS.Web.Reports.LookupTongHop" %>
<script language="javascript" src="Common/paging.js"></script>
<table id="tbl" class="Table_Border" style="border-collapse: collapse" cellspacing="0"
    cellpadding="0" width="98%" border="0" align="center">
    <tr valign="top">
        <td valign="top" align="center" height="40px" class="Title">
            BÁO CÁO ĐƠN THƯ TỔNG HỢP</td>
    </tr>
    <tr>
        <td width="100%">
            <table id="tblThongTinChung" class="Grid_Border"
                cellspacing="0" cellpadding="3" width="100%" border="0">
                <tbody>
                    <tr>
                        <td valign="middle" align="left" class="Col_Left">
                            Tìm kiếm cho</td>
                        <td class="Col_Right" valign="middle" colspan="2">
                            <input type="radio" id="radStatus1" name="radStatus" value="True" checked>Tất cả
                            <input type="radio" id="radStatus2" name="radStatus" value="False">Một trong các
                            điều kiện sau                            
                        </td>
                    </tr>
                    <tr>
                        <td class="Col_Left">Địa bàn xảy ra vụ việc:</td>
                        <td class="Col_Right" align="left" colspan="2">
			                <asp:textbox id="drpDiaBan" runat="server" CssClass="TextBox" Width="67%" MaxLength="250" ReadOnly="true"></asp:textbox>
			                <img src="Images/scroll2.png" style="display:; cursor: pointer; cursor: hand;" onclick="openSelectMultiDiaBanWindow('<% =drpDiaBan.ClientID%>','<%=hidDiaBan.ClientID %>');" />
			                <asp:HiddenField ID="hidDiaBan" runat="server" Value="0"/>
			            </td>
                    </tr>                    
                    <tr>
                        <td class="Col_Left">Cơ quan giải quyết đơn:</TD>
			            <td class="Col_Right" colspan="2">
			        	    <asp:DropDownList ID="drpPB" runat="server" Height="22" CssClass="TextBox" Width="36%" DataValueField="ID" DataTextField="TenPhongBan">
			        	    </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
		                <td class="Col_Left">Phân loại:</TD>
			            <td class="Col_Right" colspan="2">
			        	    <asp:DropDownList ID="drpLoaiDon" runat="server" Height="22" CssClass="TextBox" Width="36%" DataValueField="ID" DataTextField="TenLoaiDon"></asp:DropDownList>
                        </td>                        
                    </tr>
                    <tr>
                        <td class="Col_Left">Trạng thái xử lý:</td>
			            <td class="Col_Right" colspan="2">
			        	   <asp:DropDownList ID="drpTrangThaiXL" runat="server" CssClass="ListBox" Width="36%">
			        	   <asp:ListItem Value=""></asp:ListItem>
                            <asp:ListItem Value="1">Chưa xử lý</asp:ListItem>
                            <asp:ListItem Value="3">Đã xử lý</asp:ListItem>
                        </asp:DropDownList>	
                        </td>
                    </tr>
                    <tr>
                        <td class="Col_Left">
                            Tên người gửi đơn
                        </td>
                        <td class="Col_Right" colspan="2">
                            <asp:TextBox ID="txtField1" runat="server" MaxLength="100" Width="84%" CssClass="TextBox"></asp:TextBox>
                        </td>
                    </tr> 
                    <tr>
                        <td class="Col_Left">
                            Nội dung đơn
                        </td>
                        <td class="Col_Right" colspan="2">
                            <asp:TextBox ID="txtField2" runat="server" MaxLength="100" Width="84%" CssClass="TextBox"></asp:TextBox>
                        </td>
                    </tr> 
                    <tr>
                        <td class="Col_Left">Theo ngày</td>
                        <td colspan="2" class="Col_Right">
                            Từ ngày&nbsp;<asp:TextBox id="txtNgay1" runat="server" MaxLength="10" Width="20%" CssClass="TextBox"></asp:TextBox>
                            &nbsp;Đến ngày&nbsp;
                            <asp:TextBox id="txtNgay2" runat="server" MaxLength="10" Width="20%" CssClass="TextBox"></asp:TextBox>
                        </td>
                    </tr>      
                    <tr>
                        <td width="20%">
                        </td>
                        <td colspan="2" align="left" style="padding-top: 10px">
                            <input type="button" class="Button" value="Tìm kiếm" onclick="findDocuments();" />
                            <input type="reset" class="Button" value="Nhập lại" style="width: 90px;" language="javascript" onclick="resetValue();"/>
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr>
        <td class="Text_Main" height="30px" valign="middle">
            &nbsp;&nbsp;Kết quả: <span id="dt_Count" class="Document_Total">0</span> đơn thư.&nbsp;<!--Có <span id="dtDonDaXL" class="Document_Total">0</span> đơn đã xử lý, và <span id="dtDonChuaXL" class="Document_Total">0</span> đơn chưa xử lý.-->
        </td>
    </tr>
    <!-- Ket qua -->
    <tbody id="tbdResults" style="display: none" valign="top">        
        <tr valign="top">
            <td class="Col_Right" align="left" height="200px" valign="top" width="100%">
                <table id="tblList" class="Grid_Border" cellspacing="0" cellpadding="3" width="100%" border="0">
                    <tr class="Row_Document_Title">
                        <td width="10px" align="center">
                            STT
                        </td>
                        <td width="80px" align="center">
                            Ngày lập
                        </td>
                        <td width="80px" align="center">
                            Ngày hoàn thành
                        </td>
                         <td width="100px" align="center">
                            Nguồn đơn
                        </td>
                        <td width="100px" align="left">
                            Người gửi
                        </td>
                        <td width="110px" align="left">
                            Địa chỉ
                        </td>                        
                        <td width="100px" align="left">
                            Địa bàn xảy ra vụ việc
                        </td>
                        <td width="80px" align="left">
                            Phân loại
                        </td>
                        <td align="left">
                            Nội dung
                        </td>
                        <td width="60px" align="left">
                            Lần gửi đơn
                        </td>
                        <td width="100px" align="left">
                            Văn bản giao nhiệm vụ
                        </td>
                        <td width="100px" align="left">
                            Cơ quan giải quyết
                        </td>
                        <td width="120px" align="left">
                            Kết quả giải quyết
                        </td>
                        <td width="10px" align="center">                        
                        </td>
                    </tr>
                    <tbody id="dt_Body" style="display: none">
                        <tr id="dt_Pattern" style="display: none">
                            <td id="soSTT" style="height: 19px">
                            </td>
                            <td id="donDeNgay">
                            </td>
                            <td id="tdNgayHT">
                            </td>
                            <td id="tdNguonDon">
                            </td>              
                            <td id="tdNguoiGui">
                            </td>
                            <td id="tdDiaChi">
                            </td>
                            <td id="tdDiaBan">
                            </td>    
                            <td id="tdPhanLoai">
                            </td>            
                            <td id="tdNoiDung">
                            </td>
                            <td id="tdLanGui">
                            </td>
                              <td id="tdVanBan">
                            </td>
                            <td id="tdPhongBan">
                            </td>                            
                           <td id="tdKetQua">
                            </td>
                            <td></td>
                        </tr>
                        <tr id="dt_Page">
                            <td colspan="8">
                            </td>
                            <td id="display_Paging" align="right" class="Paging_NotLink" colspan="6">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr class="Row_Button">
            <td align="right">
                <input type="button" class="Button" value="Xem in" onclick="OpenPrinter()" />
            </td>
        </tr>
    </tbody>
</table>

<script language="javascript" type="text/javascript">  
    jQuery(function($){
        $("#<%=txtNgay1.ClientID %>").datepicker();
        $("#<%=txtNgay2.ClientID %>").datepicker();
    });
    var txtField1 = "",txtField2 = "";
    var txtNgay1 = "", txtNgay2 = "";
    var searchType;
    var cmbNguon = -1,cmbTTXL = 0;
    var cmbPB = "", cmbLoaiDon = 0, cmbDiaBan = "0";
    paging.recordsPerPage = 15;
    var pagCurrentIndex = 0;
    var resultCache = [];
    
    function findDocuments()
    {      
        paging.id = "dt_Page";
        paging.bodyId = "dt_Body";
        paging.patternId = "dt_Pattern";
        paging.filter = "";

        GetValueOfVars();         
       
        if (CheckValidation())
        {            
            CMS.Presenters.Presenters.LookupSourcePresenter.TotalSearchDonThus(searchType, txtField1,txtField2,
                                txtNgay1, txtNgay2, cmbPB, cmbLoaiDon, cmbDiaBan, cmbNguon, cmbTTXL, function(response){
                if(response != null && response.value != null) 
                {                        
                    var dtList2 = response.value; 
                    paging.totalRecords = dtList2[0];                     
                    $('#dt_Count').html(paging.totalRecords);   
                    //$('#dtDonDaXL').html((dtList2[1]==0)?"0":dtList2[1]);
                    //$('#dtDonChuaXL').html((dtList2[2]==0)?"0":dtList2[2]);                  
                    $("#display_Paging").html(paging.limitPage(1, 0));                 
                    
                    if (dtList2[0] > 0)                    
                    {
                        renderList(1);
                        $("#" + paging.bodyId).attr("style", "display:");
                        $('#tbdResults').attr("style", "display:");                        
                    }
                    else
                    {
                        $('#dt_Count').html("0");
                        //$('#dtDonDaXL').html("0");
                        //$('#dtDonChuaXL').html("0");                        
                        $("#" + paging.bodyId).attr("style", "display:none");
                        $('#tbdResults').attr("style", "display:none");  
                    }
                }
            });  
        }
    }
    
    function renderList(pageCurrent){
        var fromIndex = (pageCurrent > 1) ? (pageCurrent - 1) : 0;
        pagCurrentIndex = fromIndex;
        CMS.Presenters.Presenters.LookupSourcePresenter.SearchDonThus(searchType, txtField1,txtField2,
                        txtNgay1, txtNgay2, cmbPB, cmbLoaiDon, cmbDiaBan, cmbNguon, cmbTTXL,
                        fromIndex*paging.recordsPerPage, paging.recordsPerPage, function(response)
        {
            subRenderList(response);
        });        
    }
    
    function subRenderList(response){
        $("#" + paging.patternId).attr("style", "display:none");
        util.removeAllRows(paging.bodyId, { filter:function(tr) {
            return (tr.id != paging.patternId && tr.id != paging.id);
        }});
        var orderStart = pagCurrentIndex*paging.recordsPerPage;
        if(response.value != null)
        {                        
            var dtList = response.value; 
            var cssClass = $("#" + paging.bodyId).attr("className");
            cssClass = "Row_Document_Odd";
            var STT = orderStart;
            for (var i = 0; i < dtList.length; i++) { 
                STT++;
                var dt = {
                    ID: dtList[i][0],
                    DonDeNgay: dtList[i][1],
                    NguonDon: dtList[i][2],
                    NguoiGui: dtList[i][3],
                    DiaChi: dtList[i][4],
                    DiaBan: dtList[i][5],
                    NoiDung: dtList[i][6],
                    LanGui: dtList[i][7],
                    DVGiaiQuyet: dtList[i][8],
                    KetQua: dtList[i][9],
                    NgayHoanThanh: dtList[i][10],
                    VBGNV: dtList[i][11],
                    TenLoaiDon: dtList[i][12]
                }
                resultCache[dt.ID] = dt;
                util.cloneNode("dt_Pattern", { idSuffix:dt.ID }); 
                $("#soSTT" + dt.ID).html(STT);
                $("#donDeNgay" + dt.ID).html((dt.DonDeNgay!=null)?util.convertDateVN(dt.DonDeNgay):"");
                $("#tdNgayHT" + dt.ID).html((dt.NgayHoanThanh!=null)?util.convertDateVN(dt.NgayHoanThanh):"");
                $("#tdNguonDon" + dt.ID).html(dt.NguonDon);
                $("#tdNguoiGui" + dt.ID).html(dt.NguoiGui);
                $("#tdDiaChi" + dt.ID).html(dt.DiaChi);
                $("#tdDiaBan" + dt.ID).html(dt.DiaBan);
                $("#tdPhanLoai" + dt.ID).html(dt.TenLoaiDon);
                $("#tdNoiDung" + dt.ID).html(dt.NoiDung);
                $("#tdLanGui" + dt.ID).html(dt.LanGui);
                $("#tdVanBan" + dt.ID).html(dt.VBGNV);
                $("#tdPhongBan" + dt.ID).html(dt.DVGiaiQuyet);
                $("#tdKetQua" + dt.ID).html(dt.KetQua);
                //$("#hoTen" + dt.ID).html("<a onclick='ViewDetail(\""+ dt.ID +"\")' class='DocumentLink' href='#'>" + dt.HoTen + "</a>");                
                
//               if ($("#EDIT" + dt.ID)){
//                $("#EDIT" + dt.ID).html("<%if (this.IsHuyDonThu()) { %><a class='Link-button' href=\"<%=FullBaseUrl%>default.aspx?tabID=1&fName=16&action=EDIT&objID="+ dt.ID +"\">" +
//                        "<img src=\"Images/Icon_Compose.gif\" border=\"0\"/></a><%}%>");        
//                        
//                }
                             
                $("#" + paging.patternId + dt.ID).attr("className", cssClass);
                $("#" + paging.patternId + dt.ID).attr("style", "display:");  
                cssClass = (cssClass == "Row_Document_Round") ? "Row_Document_Odd" : "Row_Document_Round";     
            } 
        }
        
        $("#" + paging.bodyId).attr("style", "display:");
        $('#tbdResults').attr("style", "display:");
        //load_resize();
    }    
    
    function gotoPage(pageCurrent, base) {  
        renderList(pageCurrent);
        pt = paging.limitPage(pageCurrent, base);
        $("#display_Paging").html(pt);
    }   
    
    
    function GetValueOfVars()
    {           
        if ($("#radStatus1").attr("checked"))
        {
            searchType = "AND";
        }
        else
        {
            searchType = "OR";
        }        
        
        if ($("#<%=drpPB.ClientID%>").val() == "0")
        {
            cmbPB = "";
        } else {
            cmbPB = $("#<%=drpPB.ClientID%>").val();
        }
        cmbNguon = -1;  
        
         if ($("#<%=drpTrangThaiXL.ClientID%>").val() == "")
        {
            cmbTTXL = 0;
        } else {
            cmbTTXL = $("#<%=drpTrangThaiXL.ClientID%>").val();
        }
        
        if ($("#<%=drpLoaiDon.ClientID%>").val() == "")
        {
            cmbLoaiDon = 0;
        } else {
            cmbLoaiDon = parseInt($("#<%=drpLoaiDon.ClientID%>").val());
        }
        
        cmbDiaBan = $('#<%=hidDiaBan.ClientID %>').val();
        
        txtField1 = util.Trim($('#<%=txtField1.ClientID %>').val());
        txtField2 = util.Trim($('#<%=txtField2.ClientID %>').val());        
        
        txtNgay1 = util.Trim($('#<%=txtNgay1.ClientID %>').val());
        txtNgay2 = util.Trim($('#<%=txtNgay2.ClientID %>').val());        
    }
    
    function CheckValidation()
    { 
        if (txtField1 == "" && txtField2 == "" && txtNgay1 == "" && txtNgay2 == "" &&
            cmbPB == 0 && cmbLoaiDon == 0  && cmbDiaBan == "0" && cmbTTXL == 0)
        {
            alert("Xin vui lòng chọn điều kiện tìm kiếm!");
            return false;
        } 
       
        if (($('#<%=txtNgay1.ClientID%>').val() != "") && (!util.isDate($('#<%=txtNgay1.ClientID%>').val())))
        {
            alert("Từ ngày không hợp lệ!");
            $('#<%=txtNgay1.ClientID%>').focus();
            return false;
        }
        
        if (($('#<%=txtNgay2.ClientID%>').val() != "") && (!util.isDate($('#<%=txtNgay2.ClientID%>').val())))
        {
            alert("Đến ngày không hợp lệ!");
            $('#<%=txtNgay2.ClientID%>').focus();
            return false;
        }
        
        return true;
    }   
    
    function isNumberKey(e)
     {  /*Grabbing the unicode value of the key that was pressed*/
        var unicode;
        var result = true;        
        try
        {   /*IE*/
            unicode = event.keyCode; 
        }
        catch(err)
        {   
            try
            { /*Netscape, Mozilla, FireFox...*/
                 unicode = event.keyCode;
            }
            catch(error)
            {  /*Other*/
                unicode = e.which;
             }
         }
        /*if the value entered is not a unicode value between 48 and 57 return false*/
        if(unicode < 48 || unicode > 57)
        {  
            result = false;
        }          
     }
     
     function OpenPrinter()
     {          
        var strVars = "?type=" + searchType;
        strVars += "&txt1=" + txtField1; 
        strVars += "&txt2=" + txtField2; 
        strVars += "&txtNgay1=" + txtNgay1;
        strVars += "&txtNgay2=" + txtNgay2;        
        strVars += "&cmbPB=" + cmbPB;
        strVars += "&cmbNguon=" + cmbNguon;
        strVars += "&cmbTTXL=" + cmbTTXL;
        strVars += "&cmbLoaiDon=" + cmbLoaiDon;
        strVars += "&cmbDiaBan=" + cmbDiaBan;
        strVars += "&mod=TH";
       
        var strTypeReport = "Reports/LookupReportView.aspx";
        strFeatures = 'width=800px,height=600px,top=100px,left=100px,titlebar=1,menubar=0,toolbar=0,resizable=1,status=1,scrollbars=1,dependent=yes';
        window.open(strTypeReport + strVars,'_blank',strFeatures);
        return false;
    } 
    
    function resetValue()
    {
        $('#<%=hidDiaBan.ClientID %>').val(0);        
        cmbDiaBan = "0";    
    }
    function getNguonDon(id){
        result = "";
        if (id==1){
            result = "Bưu điện";
        }else if (id==2){
            result = "Trực tiếp";
        }else if (id==3){
            result = "Đơn vị khác";
        }else{
            result = "N/A";
        }
        return result;
    }
</script>

